package com.cskaoyan.dbutils;

import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 创建日期: 2022/08/29 10:31
 *
 * @author ciggar
 */
public class MyResultSetHandler implements ResultSetHandler {
    @Override
    public Object handle(ResultSet resultSet) throws SQLException {

        if (resultSet.next()) {

            int id = resultSet.getInt("id");
            String username = resultSet.getString("username");
            String password = resultSet.getString("password");
            String nickname = resultSet.getString("nickname");

            User user = new User();

            user.setId(id);
            user.setUsername(username);
            user.setPassword(password);
            user.setNickname(nickname);

            return user;

        }else {
            return null;
        }


    }
}
